/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AviPostPanel.java
 *
 * Created on 24/04/2011, 12:36:47
 */

package presentation.gui;

import domain.ClientController;

/**
 *
 * @author yedidim
 */
public class PostPanel extends javax.swing.JPanel {
       private ClientController _clientController;
       private String _forunId;
       private String _threadId;
       private String _post_id;
	private String _title;
	private String _body;
	private String _owner;
	private String _thread_id;
	private String _dateTime;
        private  StartWindow _start;

    /** Creates new form Post */
    public PostPanel(ClientController clientController,String forumId,String threadId, String title1,
            String body1 , String owner ,String date1,String post_id,StartWindow start) {
     this._clientController=clientController;
        this._post_id=post_id;
        this._title=title1;
        this._body=body1;
        this._owner=owner;
        this._dateTime=date1;
        this._thread_id=threadId;
        this._forunId=forumId;
        this._threadId=threadId;
        this._start=start;
        initComponents();

        author.setText(owner);
        date.setText(_dateTime);
        title.setText(title1);
        title.setEditable(false);
        body.setText(body1);
        body.setEditable(false);
        //TODO add if statement to check if the user is the owner of the post
        if(!this.getController().getCurrentLogedInUsername().equals(this.getOwner()))
        {
           editBtm.setVisible(false);
           remove.setVisible(false);
        }
        setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane2 = new javax.swing.JLayeredPane();
        author = new javax.swing.JLabel();
        date = new javax.swing.JLabel();
        title = new javax.swing.JTextField();
        remove = new javax.swing.JButton();
        editBtm = new javax.swing.JButton();
        back = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        body = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(1000, 403));

        jLayeredPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Forum System", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Kristen ITC", 3, 14), new java.awt.Color(255, 255, 255))); // NOI18N

        author.setFont(new java.awt.Font("Kristen ITC", 1, 14)); // NOI18N
        author.setForeground(new java.awt.Color(255, 255, 255));
        author.setText("Author");
        author.setBounds(110, 60, 80, 20);
        jLayeredPane2.add(author, javax.swing.JLayeredPane.DEFAULT_LAYER);

        date.setFont(new java.awt.Font("Kristen ITC", 1, 14));
        date.setForeground(new java.awt.Color(255, 255, 255));
        date.setText("Date: ");
        date.setBounds(270, 60, 170, 20);
        jLayeredPane2.add(date, javax.swing.JLayeredPane.DEFAULT_LAYER);

        title.setFont(new java.awt.Font("Kristen ITC", 1, 18));
        title.setEnabled(false);
        title.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                titleActionPerformed(evt);
            }
        });
        title.setBounds(40, 80, 410, 31);
        jLayeredPane2.add(title, javax.swing.JLayeredPane.DEFAULT_LAYER);

        remove.setFont(new java.awt.Font("Kristen ITC", 1, 14)); // NOI18N
        remove.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/gui/pics/Close-icon.png"))); // NOI18N
        remove.setText("Remove");
        remove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeActionPerformed(evt);
            }
        });
        remove.setBounds(260, 340, 140, 33);
        jLayeredPane2.add(remove, javax.swing.JLayeredPane.DEFAULT_LAYER);

        editBtm.setFont(new java.awt.Font("Kristen ITC", 1, 14)); // NOI18N
        editBtm.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/gui/pics/Edit-Users-icon.png"))); // NOI18N
        editBtm.setText("Edit");
        editBtm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editBtmActionPerformed(evt);
            }
        });
        editBtm.setBounds(80, 340, 130, 33);
        jLayeredPane2.add(editBtm, javax.swing.JLayeredPane.DEFAULT_LAYER);

        back.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/gui/pics/go_back.png"))); // NOI18N
        back.setBorder(null);
        back.setBorderPainted(false);
        back.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backActionPerformed(evt);
            }
        });
        back.setBounds(20, 20, 40, 30);
        jLayeredPane2.add(back, javax.swing.JLayeredPane.DEFAULT_LAYER);

        body.setColumns(20);
        body.setFont(new java.awt.Font("Kristen ITC", 1, 14));
        body.setRows(5);
        body.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        body.setEnabled(false);
        jScrollPane1.setViewportView(body);

        jScrollPane1.setBounds(40, 110, 410, 200);
        jLayeredPane2.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel1.setFont(new java.awt.Font("Kristen ITC", 1, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Author:");
        jLabel1.setBounds(40, 60, 80, 20);
        jLayeredPane2.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 485, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(496, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 456, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void titleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_titleActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_titleActionPerformed

    private void editBtmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editBtmActionPerformed
    
      getStart().getForum().displayForum(  new EditPostPanel(this.getController(),this.getForumId(),
                                                                                                                                       this.getThreadId(),this.getPostId(),this.getTitle(),this.getBody(),this.getStart()));
}//GEN-LAST:event_editBtmActionPerformed

    private void removeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeActionPerformed
      this.getController().RemovePost(this.getThreadId(), this.getPostId());
      getStart().getForum().displayForum(  new PostsViewPanel(this.getController(), this.getForumId(), this.getThreadId(), this.getStart()));

    }//GEN-LAST:event_removeActionPerformed

    private void backActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backActionPerformed
        // Back Button
        this.setVisible(false);
        //getStartWindow().nonDisplayForum(); //setVisible false
        getStart().getForum().displayForum( new PostsViewPanel(this.getController(), this.getForumId(), this.getThreadId(), this.getStart()));
        this.setVisible(false);
}//GEN-LAST:event_backActionPerformed

 public ClientController getController(){
     return this._clientController;
 }
 public String  getOwner(){
     return this._owner;
 }

 public String  getForumId(){
     return this._forunId;
 }
 public String getTitle(){
     return this._title;
 }
public String getBody(){
    return this._body;
}
 public String  getThreadId(){
     return this._threadId;
 }

  public String  getPostId(){
     return this._post_id;
 }


 public StartWindow  getStart(){
     return this._start;
 }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel author;
    private javax.swing.JButton back;
    private javax.swing.JTextArea body;
    private javax.swing.JLabel date;
    private javax.swing.JButton editBtm;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton remove;
    private javax.swing.JTextField title;
    // End of variables declaration//GEN-END:variables

}
